<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui" 
      xmlns:s="http://myfaces.apache.org/sandbox">

<head>
</head>
<body>

	<ui:composition template="../WEB-INF/layout/template.xhtml">
		<ui:define name="title"><h:outputText value="#{msg.add_school}" /></ui:define>
		<ui:define name="content">

			<div style="width:750px;margin:auto;">
			
				<p:tabView id="tabview">
					<p:tab title="#{msg.school}">
						<h:form id="schoolForm">
							<p:fieldset legend="#{msg.school_details}">
								<small><h:outputText value="#{msg.mandatory_fields}"/></small>
								<p:fieldset id="generalitiesFieldsed" legend="#{msg.generalities}">
									<h:panelGrid columns="3">
										<h:outputText value="#{msg.name}" />
										<p:inputText id="name" value="#{inserisciScuolaBean.schoolInput.ragioneSociale}" required="true">
											<f:validator for="name" validatorId="genericNameValidator" />
										</p:inputText>
										<p:message for="name" style="color:red;"/>
										<h:outputText value="#{msg.web_address}" />
										<p:inputText id="web" value="#{inserisciScuolaBean.schoolInput.webSite}" >
											<f:validator validatorId="urlValidator"/>
										</p:inputText>
										<p:message for="web" style="color:red;"/>
										<h:outputText value="#{msg.ongoing_contract}" />
										<h:selectOneMenu id="ongoing" value="#{inserisciScuolaBean.schoolInput.contrattoInCorso}">
											<f:selectItem id="yes" itemLabel="#{msg.yes}" itemValue="#{inserisciScuolaBean.schoolInput.contrattoInCorso}"/>
											<f:selectItem id="no" itemLabel="#{msg.no}" itemValue="#{inserisciScuolaBean.schoolInput.contrattoInCorso}"/>
										</h:selectOneMenu>
										<p:message for="ongoing" style="color:red;"/>
									</h:panelGrid>
								</p:fieldset>
				
								<p:fieldset id="emailsFieldset" legend="#{msg.emails}">
									<h:dataTable id="emailTable" value="#{inserisciScuolaBean.schoolInput.emails}" var="email">
										<h:column>
											<h:outputText value="#{msg.email}: "/>
										</h:column>
										<h:column>
											<p:inputText id="email" value="#{email.email}" required="true">
												<f:validateLength minimum="5" maximum="50"/>
												<f:validator validatorId="emailValidator"/>
											</p:inputText>
										</h:column>
										<h:column>
											<h:selectOneMenu value="#{email.type}">
												<f:selectItems value="#{inserisciScuolaBean.emailTypeOptions}"/>
											</h:selectOneMenu>
										</h:column>
										<h:column>
											<p:commandLink process="@this" value="#{msg.delete}" update="schoolForm" action="#{inserisciScuolaBean.removeEmail}" >
												<f:setPropertyActionListener value="#{email}" target="#{inserisciScuolaBean.emailToRemove}" />
											</p:commandLink>
										</h:column>
										<h:column>
											<p:message for="email" style="color:red;"/>
										</h:column>
									</h:dataTable>
									<p:commandLink value="#{msg.add_email}" update="growl schoolForm" action="#{inserisciScuolaBean.addEmptyEmail}"/>								
								</p:fieldset>
				
								<p:fieldset id="phonesFieldset" legend="#{msg.phones}">
									<h:dataTable value="#{inserisciScuolaBean.schoolInput.telephones}" var="telephone">
										<h:column>
											<h:outputText value="#{msg.number}: "/>
										</h:column>
										<h:column>
											<p:inputText id="number" value="#{telephone.number}" required="true">
												<f:validator validatorId="telefonoValidator"/>
											</p:inputText>
										</h:column>
										<h:column>
											<h:selectOneMenu value="#{telephone.type}">
												<f:selectItems value="#{inserisciScuolaBean.phoneTypeOptions}"/>
											</h:selectOneMenu>
										</h:column>
										<h:column>
											<h:selectOneMenu value="#{telephone.country}">
												<f:selectItems value="#{inserisciScuolaBean.phoneCountryOptions}"/>
											</h:selectOneMenu>
										</h:column>
										<h:column>
											<p:commandLink value="#{msg.delete}" process="@this" update="#{p:component('schoolForm')}" action="#{inserisciScuolaBean.removeTelephone}" >
												<f:setPropertyActionListener value="#{telephone}" target="#{inserisciScuolaBean.telephoneToRemove}" />
											</p:commandLink>
										</h:column>
										<h:column>
											<p:message for="number" style="color:red;"/>
										</h:column>
									</h:dataTable>
									<p:commandLink value="#{msg.add_phone}" update="growl schoolForm" action="#{inserisciScuolaBean.addEmptyPhone}"/>
								</p:fieldset>
						
								<p:fieldset id="faxesFieldsed" legend="#{msg.faxes}">
									<h:dataTable value="#{inserisciScuolaBean.schoolInput.faxes}" var="fax">
										<h:column>
											<h:outputText value="#{msg.number}: "/>
										</h:column>
										<h:column>
											<p:inputText id="number" value="#{fax.number}" required="true">
												<f:validator validatorId="telefonoValidator"/>
											</p:inputText>
										</h:column>
										<h:column>
											<p:commandLink value="#{msg.delete}" process="@this" update="#{p:component('schoolForm')}" action="#{inserisciScuolaBean.removeFax}" >
												<f:setPropertyActionListener value="#{fax}" target="#{inserisciScuolaBean.faxToRemove}" />
											</p:commandLink>
										</h:column>
										<h:column>
											<p:message for="number" style="color:red;"/>
										</h:column>
									</h:dataTable>
									<p:commandLink value="#{msg.add_fax}" update="growl schoolForm" action="#{inserisciScuolaBean.addEmptyFax}"/>
								</p:fieldset>
					
								<p:fieldset id="auAddressFieldsed" legend="#{msg.au_address}">
									<h:panelGrid columns="3">
										<h:outputText value="#{msg.address_line_1}: "/>
										<p:inputText id="indirizzoLinea1Au" value="#{inserisciScuolaBean.schoolInput.indirizzo.indirizzoLinea1}">
										</p:inputText>
										<p:message for="indirizzoLinea1Au" style="color:red;"/>
		
										<h:outputText value="#{msg.address_line_2}: "/>
										<p:inputText id="indirizzoLinea2Au" value="#{inserisciScuolaBean.schoolInput.indirizzo.indirizzoLinea2}">
										</p:inputText>
										<p:message for="indirizzoLinea2Au" style="color:red;"/>
		
										<h:outputText value="#{msg.town}: "/>
										<p:inputText id="cittaAu" value="#{inserisciScuolaBean.schoolInput.indirizzo.citta}">
											<f:validator validatorId="genericNameValidator" style="color:red;"/>
										</p:inputText>
										<p:message for="cittaAu" style="color:red;"/>
		
										<h:outputText value="#{msg.state}: "/>
										<h:selectOneMenu id="stato" value="#{inserisciScuolaBean.schoolInput.indirizzo.stato}">
											<f:selectItems value="#{inserisciScuolaBean.stateOptions}"/>		
										</h:selectOneMenu>
										<p:message for="stato" style="color:red;"/>
			
										<h:outputText value="#{msg.post_code}: "/>
										<p:inputText id="postCode" value="#{inserisciScuolaBean.schoolInput.indirizzo.postCode}">
											<f:validator validatorId="postCodeValidator" style="color:red;"/>		
										</p:inputText>
										<p:message for="postCode" style="color:red;"/>
		
										<h:outputText value="#{msg.country}: "/>
										<p:inputText id="paeseAu" value="#{inserisciScuolaBean.schoolInput.indirizzo.paese}">
											<f:validator validatorId="genericNameValidator" style="color:red;"/>		
										</p:inputText>
										<p:message for="paeseAu" style="color:red;"/>
									</h:panelGrid>
								</p:fieldset>
						
								<p:commandButton ajax="false" process="@all" value="#{msg.submit}" action="#{inserisciScuolaBean.submit}"/>
									
							</p:fieldset>
						</h:form>
					</p:tab>

					<p:tab title="#{msg.branches}">
						<h:form id="tableForm">
							<p:dataTable id="table" value="#{inserisciScuolaBean.schoolInput.branches}" var="branch">
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.name}" />
									</f:facet>
									<h:outputText value="#{branch.name}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.address_line_1}" />
									</f:facet>
									<h:outputText value="#{branch.indirizzo.indirizzoLinea1}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.address_line_2}" />
									</f:facet>
									<h:outputText value="#{branch.indirizzo.indirizzoLinea2}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.town}" />
									</f:facet>
									<h:outputText value="#{branch.indirizzo.citta}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.state}" />
									</f:facet>
									<h:outputText value="#{branch.indirizzo.stato}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.post_code}" />
									</f:facet>
									<h:outputText value="#{branch.indirizzo.postCode}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.country}" />
									</f:facet>
									<h:outputText value="#{branch.indirizzo.paese}" />
								</p:column>
							</p:dataTable>
						</h:form>
						<p:panel>
							<h:form id="pform">
								<p:commandButton value="#{msg.add}" onclick="dlg.show()" />
							</h:form>
						</p:panel>
					</p:tab>
					<p:tab title="#{msg.contacts}">
						<h:form id="contactsTableForm">
							<p:dataTable id="contactsTable" value="#{inserisciScuolaBean.schoolInput.contattiDiRiferimento}" var="contact">
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.first_name}" />
									</f:facet>
									<h:outputText value="#{contact.firstName}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.middle_name}" />
									</f:facet>
									<h:outputText value="#{contact.middleName}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.surname}" />
									</f:facet>
									<h:outputText value="#{contact.surname}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.branch}" />
									</f:facet>
									<h:outputText value="#{contact.branch.name}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.role}" />
									</f:facet>
									<h:outputText value="#{contact.ruolo}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.emails}" />
									</f:facet>
									<p:dataTable value="#{contact.emails}" var="email">
										<p:column>
											<f:facet name="header">
												<h:outputText value="#{msg.email}" />
											</f:facet>
											<h:outputText value="#{email.email}" />
										</p:column>
										<p:column>
											<f:facet name="header">
												<h:outputText value="#{msg.type}" />
											</f:facet>
											<h:outputText value="#{email.type}" />
										</p:column>
									</p:dataTable>
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.phones}" />
									</f:facet>
									<p:dataTable value="#{contact.telephones}" var="telephone">
										<p:column>
											<f:facet name="header">
												<h:outputText value="#{msg.number}" />
											</f:facet>
											<h:outputText value="#{telephone.number}" />
										</p:column>
										<p:column>
											<f:facet name="header">
												<h:outputText value="#{msg.type}" />
											</f:facet>
											<h:outputText value="#{telephone.type}" />
										</p:column>
									</p:dataTable>
								</p:column>
							</p:dataTable>
						</h:form>
						<p:panel>
							<h:form id="pform2">
								<p:commandButton value="#{msg.add}" onclick="dlg2.show()" />
							</h:form>
						</p:panel>
					</p:tab>
					
					<p:tab title="#{msg.courses}">
						<h:form id="coursesForm">
							<p:dataTable id="coursesTable" value="#{inserisciScuolaBean.courses}" var="course">
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.name}" />
									</f:facet>
									<h:outputText value="#{course.name}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.code}" />
									</f:facet>
									<h:outputText value="#{course.codice}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.description}" />
									</f:facet>
									<h:outputText value="#{course.description}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.subscription_fee}" />
									</f:facet>
									<h:outputText value="#{course.subscriptionFee}#{course.subscriptionFeeCurrency}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.category}" />
									</f:facet>
									<h:outputText value="#{course.categoria.name}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.branches}" />
									</f:facet>
									<p:dataTable value="#{course.sedi}" var="branch">
										<p:column>
											<f:facet name="header">
												<h:outputText value="#{msg.branch}" />
											</f:facet>
											<h:outputText value="#{branch.name}, #{branch.indirizzo.indirizzoLinea1}, #{branch.indirizzo.citta}"/>
										</p:column>
									</p:dataTable>
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.costs}" />
									</f:facet>
									<p:dataTable value="#{course.costi}" var="cost">
										<p:column>
											<f:facet name="header">
												<h:outputText value="#{msg.weeks}" />
											</f:facet>
											<h:outputText value="#{cost.minWeeks} - #{cost.maxWeeks}"/>
										</p:column>
										<p:column>
											<f:facet name="header">
												<h:outputText value="#{msg.price}" />
											</f:facet>
											<h:outputText value="#{cost.weeklyPrice}#{cost.currency}"/>
										</p:column>
									</p:dataTable>
								</p:column>
							</p:dataTable>
						</h:form>
						<p:panel>
							<h:form id="pform3">
								<p:commandButton value="#{msg.add}" onclick="dlg3.show()" />
							</h:form>
						</p:panel>
					</p:tab>
					<p:tab title="#{msg.study_material}">
						<h:form id="studyMaterialForm">
							<h:panelGrid columns="3">
								<h:outputText value="#{msg.description}"/>
								<p:inputText id="smDesc" value="#{inserisciScuolaBean.schoolInput.studyMaterial.description}"/>
								<p:message for="smDesc"/>
								<h:outputText value="#{msg.price}"/>
								<p:inputText id="smPrice" value="#{inserisciScuolaBean.schoolInput.studyMaterial.pricePolicy.price}">
									<f:convertNumber for="smPrice" maxFractionDigits="2"  minIntegerDigits="1" type="currency" currencySymbol="$"/>
								</p:inputText>
								<p:message for="smPrice"/>
								<h:outputText value="#{msg.every_number_of_weeks}"/>
								<p:spinner id="smWeeks" value="#{inserisciScuolaBean.schoolInput.studyMaterial.pricePolicy.everyNumberOfWeeks}">
									<f:convertNumber for="smWeeks" maxFractionDigits="0"  minIntegerDigits="1" type="number"/>
								</p:spinner>
								<p:message for="smWeeks"/>
								<h:outputText value="#{msg.every_level_change}"/>
								<h:selectBooleanCheckbox id="smLevel" value="#{inserisciScuolaBean.schoolInput.studyMaterial.pricePolicy.forLevel}" />
								<p:message for="smLevel"/>			
							</h:panelGrid>
						</h:form>
					</p:tab>
				</p:tabView>
				
				<p:dialog id="dialog3"
					modal="true"
					header="#{msg.new_course}"
					widgetVar="dlg3"
					minWidth="700"
					onHide="document.forms['form3'].reset();">
					<h:form id="form3">
						<fieldset>
							<legend>#{msg.generalities}</legend>
							<h:panelGrid columns="3">
								<h:outputText value="#{msg.name}: *" />
								<p:inputText id="courseName" value="#{inserisciScuolaBean.courseInput.name}" required="true"/>
								<p:message for="courseName"/>
								<h:outputText value="#{msg.code}: " />
								<p:inputText id="courseCode" value="#{inserisciScuolaBean.courseInput.codice}" />
								<p:message for="courseCode"/>
								<h:outputText value="#{msg.description}: " />
								<p:inputText id="courseDescription" value="#{inserisciScuolaBean.courseInput.description}"/>
								<p:message for="courseDescription"/>
								<h:outputText value="#{msg.subscription_fee}: " />
								<p:inputText id="subscriptionFee" value="#{inserisciScuolaBean.courseInput.subscriptionFee}">
									<f:convertNumber for="subscriptionFee" maxFractionDigits="2"  minIntegerDigits="1" type="currency" currencySymbol="$"/>
								</p:inputText>
								<p:message for="subscriptionFee"/>
								<h:outputText value="#{msg.category}"/>
								<h:selectOneMenu id="macroCategorySOM" 
									value="#{inserisciScuolaBean.courseInputMacroCategoryId}">
									<f:selectItems 
										value="#{inserisciScuolaBean.macrocategories}" 
										var="macroCategory" 
										itemLabel="#{macroCategory.name}" 
										itemValue="#{macroCategory.id}"/>
									<p:ajax update="categorySOM"/>
								</h:selectOneMenu>
								<h:selectOneMenu id="categorySOM" 
									value="#{inserisciScuolaBean.courseInputCategoryId}">
									<f:selectItems 
										value="#{inserisciScuolaBean.categories}" 
										var="category" 
										itemLabel="#{category.name}" 
										itemValue="#{category.id}"/>
								</h:selectOneMenu>
							</h:panelGrid>
						</fieldset>
						<fieldset>
							<legend>#{msg.branches}</legend>
							<h:panelGrid columns="3">
								<h:outputText value="#{msg.branches}" />
								<h:selectManyListbox id="courseBranches" 
									value="#{inserisciScuolaBean.courseInputBranchesNames}"
									size="5" >
									<f:selectItems 
										value="#{inserisciScuolaBean.schoolInput.branches}" 
										var="branch" 
										itemLabel="#{branch.name}, #{branch.indirizzo.citta}, #{branch.indirizzo.indirizzoLinea1}" 
										itemValue="#{branch.name}"/>
								</h:selectManyListbox>
								<p:message for="courseBranches"/>
							</h:panelGrid>
						</fieldset>
						<fieldset>
							<legend>#{msg.costs}</legend>
							<p:dataTable id="courseCostsTable" value="#{inserisciScuolaBean.courseInput.costi}" var="cost">
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.from} *"/>
									</f:facet>
									<p:inputText id="minWeeks" value="#{cost.minWeeks}" required="true">
										<f:convertNumber for="minWeeks" maxFractionDigits="0" maxIntegerDigits="3" minIntegerDigits="1" type="number"/>
									</p:inputText>
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.to} *"/>
									</f:facet>
									<p:inputText id="maxWeeks" value="#{cost.maxWeeks}" required="true">
										<f:convertNumber for="maxWeeks" maxFractionDigits="0" maxIntegerDigits="3" minIntegerDigits="1" type="number"/>
									</p:inputText>
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.price} *"/>
									</f:facet>
									<p:inputText id="costPrice" value="#{cost.weeklyPrice}" required="true">
										<f:convertNumber for="costPrice" maxFractionDigits="2" maxIntegerDigits="5" minIntegerDigits="1" type="currency" currencySymbol="$"/>
									</p:inputText>
								</p:column>
								<p:column>
									<p:commandLink process="@this" value="#{msg.delete}" update="form3" action="#{inserisciScuolaBean.removeCourseInputCost}" >
										<f:setPropertyActionListener value="#{cost}" target="#{inserisciScuolaBean.costToRemove}" />
									</p:commandLink>
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="#{msg.messages} *"/>
									</f:facet>
									<p:message for="costPrice"/>
									<p:message for="minWeeks"/>
									<p:message for="maxWeeks"/>
								</p:column>
							</p:dataTable>
							<p:message for="courseCostsTable"/>
							<p:commandLink value="#{msg.add_cost}" update="form3 growl" action="#{inserisciScuolaBean.addEmptyCost}"/>
						</fieldset>
						<p:commandButton value="#{msg.submit}" 
									actionListener="#{inserisciScuolaBean.submitNewCourse}"
									update="growl form3 coursesForm:coursesTable"
									oncomplete="handleDialogRequest3(xhr, status, args)" />
						<p:commandButton value="#{msg.reset}" type="reset"/>
					</h:form>					
				</p:dialog>
				
				<p:dialog id="dialog2" 
					modal="true" 
					header="#{msg.new_contact}" 
					widgetVar="dlg2" 
					minWidth="500" 
					onHide="document.forms['form2'].reset();">
					<h:form id="form2">
						<fieldset>
							<legend>#{msg.generalities}</legend>
							<h:panelGrid columns="3">
								<h:outputText value="#{msg.first_name}: *" />
								<p:inputText id="firstName" value="#{inserisciScuolaBean.contactInput.firstName}" required="true"/>
								<p:message for="firstName" />
								<h:outputText value="#{msg.middle_name}: " />
								<p:inputText id="middleName" value="#{inserisciScuolaBean.contactInput.middleName}"/>
								<p:message for="middleName" />
								<h:outputText value="#{msg.surname}: *" />
								<p:inputText id="surname" value="#{inserisciScuolaBean.contactInput.surname}" required="true"/>
								<p:message for="surname" />
								<h:outputText value="#{msg.branch}: " />
								<h:selectOneMenu id="branch" value="#{inserisciScuolaBean.contactInputBranchName}">
									<f:selectItems 
										value="#{inserisciScuolaBean.schoolInput.branches}" 
										var="branch" 
										itemLabel="#{branch.name}" 
										itemValue="#{branch.name}"/>
								</h:selectOneMenu>
								<p:message for="branch" />
								<h:outputText value="#{msg.role}: " />
								<p:inputText id="role" value="#{inserisciScuolaBean.contactInput.ruolo}"/>
								<p:message for="role" />
							</h:panelGrid>
						</fieldset>
						<fieldset>
							<legend>#{msg.emails}</legend>
							<h:dataTable id="ContactEmailTable" value="#{inserisciScuolaBean.contactInput.emails}" var="email">
								<h:column>
									<h:outputText value="#{msg.email}: "/>
								</h:column>
								<h:column>
									<p:inputText id="contactEmail" value="#{email.email}" required="true">
										<f:validateLength minimum="5" maximum="50"/>
										<f:validator validatorId="emailValidator"/>
									</p:inputText>
								</h:column>
								<h:column>
									<h:selectOneMenu value="#{email.type}">
										<f:selectItems value="#{inserisciScuolaBean.emailTypeOptions}"/>
									</h:selectOneMenu>
								</h:column>
								<h:column>
									<p:commandLink process="@this" value="#{msg.delete}" update="form2" action="#{inserisciScuolaBean.removeContactEmail}" >
										<f:setPropertyActionListener value="#{email}" target="#{inserisciScuolaBean.contactEmailToRemove}" />
									</p:commandLink>
								</h:column>
								<h:column>
									<p:message for="contactEmail" style="color:red;"/>
								</h:column>
							</h:dataTable>
							<p:commandLink value="#{msg.add_email}" update="form2 growl" action="#{inserisciScuolaBean.addEmptyContactEmail}"/>								
						</fieldset>
						<fieldset>
							<legend>#{msg.phones}</legend>
							<h:dataTable id="ContactTelephoneTable" value="#{inserisciScuolaBean.contactInput.telephones}" var="telephone">
								<h:column>
									<h:outputText value="#{msg.number}: "/>
								</h:column>
								<h:column>
									<p:inputText id="contactPhoneNumber" value="#{telephone.number}" required="true">
										<f:validator validatorId="telefonoValidator"/>
									</p:inputText>
								</h:column>
								<h:column>
									<h:selectOneMenu value="#{telephone.type}">
										<f:selectItems value="#{inserisciScuolaBean.phoneTypeOptions}"/>
									</h:selectOneMenu>
								</h:column>
								<h:column>
									<h:selectOneMenu value="#{telephone.country}">
										<f:selectItems value="#{inserisciScuolaBean.phoneCountryOptions}"/>
									</h:selectOneMenu>
								</h:column>
								<h:column>
									<p:commandLink process="@this" value="#{msg.delete}" update="form2" action="#{inserisciScuolaBean.removeContactTelephone}" >
										<f:setPropertyActionListener value="#{telephone}" target="#{inserisciScuolaBean.contactTelephoneToRemove}" />
									</p:commandLink>
								</h:column>
								<h:column>
									<p:message for="contactPhoneNumber" style="color:red;"/>
								</h:column>
							</h:dataTable>
							<p:commandLink value="#{msg.add_phone}" update="form2 growl" action="#{inserisciScuolaBean.addEmptyContactPhone}"/>								
						</fieldset>
						<fieldset>
							<legend>#{msg.faxes}</legend>
							<h:dataTable id="ContactFaxTable" value="#{inserisciScuolaBean.contactInput.faxes}" var="fax">
								<h:column>
									<h:outputText value="#{msg.number}: "/>
								</h:column>
								<h:column>
									<p:inputText id="contactFaxNumber" value="#{fax.number}" required="true">
										<f:validator validatorId="telefonoValidator"/>
									</p:inputText>
								</h:column>
								<h:column>
									<p:commandLink process="@this" value="#{msg.delete}" update="form2" action="#{inserisciScuolaBean.removeContactFax}" >
										<f:setPropertyActionListener value="#{fax}" target="#{inserisciScuolaBean.contactFaxToRemove}" />
									</p:commandLink>
								</h:column>
								<h:column>
									<p:message for="contactFaxNumber" style="color:red;"/>
								</h:column>
							</h:dataTable>
							<p:commandLink value="#{msg.add_fax}" update="form2 growl" action="#{inserisciScuolaBean.addEmptyContactFax}"/>								
						</fieldset>
						<p:commandButton value="#{msg.submit}" 
									actionListener="#{inserisciScuolaBean.submitNewContact}"
									update="growl form2 contactsTableForm:contactsTable"
									oncomplete="handleDialogRequest2(xhr, status, args)" />
					</h:form>
				</p:dialog>

				<p:dialog id="dialog" 
					modal="true" 
					header="#{msg.new_branch}" 
					widgetVar="dlg" 
					onHide="document.forms['form'].reset();">
					<h:form id="form">
						<h:panelGrid columns="3">
							<h:outputText value="#{msg.name}: " />
							<p:inputText id="name" value="#{inserisciScuolaBean.branchInput.name}" required="true"/>
							<p:message for="name" />
						</h:panelGrid>
						<fieldset>
								<legend>#{msg.au_address}</legend>
								<h:panelGrid columns="3">
									<h:outputText value="#{msg.address_line_1}: "/>
									<p:inputText id="indirizzoLinea1Au" value="#{inserisciScuolaBean.branchInput.indirizzo.indirizzoLinea1}">
									</p:inputText>
									<p:message for="indirizzoLinea1Au" style="color:red;"/>
				
									<h:outputText value="#{msg.address_line_2}: "/>
									<p:inputText id="indirizzoLinea2Au" value="#{inserisciScuolaBean.branchInput.indirizzo.indirizzoLinea2}">
									</p:inputText>
									<p:message for="indirizzoLinea2Au" style="color:red;"/>
				
									<h:outputText value="#{msg.town}: "/>
									<p:inputText id="cittaAu" value="#{inserisciScuolaBean.branchInput.indirizzo.citta}">
										<f:validator validatorId="genericNameValidator" style="color:red;"/>
									</p:inputText>
									<p:message for="cittaAu" style="color:red;"/>
				
									<h:outputText value="#{msg.state}: "/>
									<h:selectOneMenu id="stato" value="#{inserisciScuolaBean.branchInput.indirizzo.stato}">
										<f:selectItems value="#{inserisciScuolaBean.stateOptions}"/>
									</h:selectOneMenu>
									<p:message for="stato" style="color:red;"/>
					
									<h:outputText value="#{msg.post_code}: "/>
									<p:inputText id="postCode" value="#{inserisciScuolaBean.branchInput.indirizzo.postCode}">
										<f:validator validatorId="postCodeValidator" style="color:red;"/>		
									</p:inputText>
									<p:message for="postCode" style="color:red;"/>
				
									<h:outputText value="#{msg.country}: "/>
									<p:inputText id="paeseAu" value="#{inserisciScuolaBean.branchInput.indirizzo.paese}">
										<f:validator validatorId="genericNameValidator" style="color:red;"/>		
									</p:inputText>
									<p:message for="paeseAu" style="color:red;"/>
								</h:panelGrid>
							</fieldset>
						<p:commandButton value="#{msg.submit}" 
									actionListener="#{inserisciScuolaBean.submitNewBranch}"
									update="growl form form2 tableForm:table dialog3"
									oncomplete="handleDialogRequest(xhr, status, args)" />
					</h:form>
				</p:dialog>
				
				<p:growl id="growl"/>

				<script type="text/javascript">
				function handleDialogRequest(xhr, status, args) {
					if(args.validationFailed) {
						jQuery('#dialog').effect("shake", { times:3 }, 100);
					} else {
						dlg.hide();
						document.forms['form'].reset();			
					}
				}
				function handleDialogRequest2(xhr, status, args) {
					if(args.validationFailed) {
						jQuery('#dialog2').effect("shake", { times:3 }, 100);
					} else {
						dlg2.hide();
						document.forms['form2'].reset();			
					}
				}
				function handleDialogRequest3(xhr, status, args) {
					if(args.validationFailed) {
						jQuery('#dialog3').effect("shake", { times:3 }, 100);
					} else {
						dlg3.hide();
						document.forms['form3'].reset();			
					}
				}
				</script>

			</div>
			
			
				
			
		</ui:define>
	</ui:composition>

</body>
</html>
